package com.demo.annotation;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ListView;

import com.demo.annotation.adapter.InfoAdapter;
import com.demo.annotation.entity.MsgInfo;
import com.yihujiu.demo.R;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by liu.hb on 2018/3/5.
 */
@EActivity(R.layout.aaframe)
public class AAFrameActivity extends Activity{
    //2.实例化控件
    @ViewById
    Button btn;

    @ViewById(R.id.lv_data)
    ListView mLvData;
    @Bean
    InfoAdapter mInfoAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }
    //3.初始化控件显示
    @AfterViews
    void initViews() {
        // 初始化控件
        btn.setText("button 按钮");
        mLvData.setAdapter(mInfoAdapter);
    }
    //4.设置控件点击事件
    @Click(R.id.btn)
    void btnClick() {
//        Toast.makeText(MainActivity.this,"aaa",Toast.LENGTH_LONG).show();
//        Intent i = new Intent(AAFrameActivity_.this,aaActivity_.class);
//        startActivity(i);
        //6.打开新的Activity
        //aaActivity_.intent(this).start(); // 不带参数
        aaActivity_.intent(this).mInfoStr("this is infoStr.").start(); // 带参数
//         aaActivity_.intent(this).msgInfo(new MsgInfo()).start(); // 带参数
//         finish();
    }
    //7.控件ListView的使用，含adapter（代码较多，请直接看Demo）
    //初始化列表信息
    private List<MsgInfo> getMsgInfo(int size) {
        List<MsgInfo> dataList = new ArrayList<>();
        MsgInfo msgInfo = null;
        for (int i = size; i > 0; i--) {
            msgInfo = new MsgInfo();
            msgInfo.id = String.valueOf(i);
            msgInfo.age = i;
            msgInfo.name = "name_" + i;
            dataList.add(msgInfo);
        }
        return dataList;
    }
    //产生一个不大于30的随机数
    @Click(R.id.btnRefreshList)
    void refreshList() {
        Random random = new Random();
        int size = random.nextInt(30);
        System.out.println(size+"sizesizesizesizesizesizesizesizesizesizesize");
        mInfoAdapter.reloadList(getMsgInfo(size));
    }

}
